package com.scale.service.character.controller;

import com.example.character.entity.AiCharacters;
import com.example.character.vo.CharacterStatusVO;
import com.example.common.result.Result;
import com.scale.service.character.service.AiCharactersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * AI角色表 前端控制器
 * </p>
 *
 * @author crp
 * @since 2025-09-24
 */
@Api(tags = "AI角色管理")
@RestController
@RequestMapping("/api/ai-characters")
@CrossOrigin(origins = {
    "http://localhost:3000", 
    "http://127.0.0.1:3000", 
    "http://localhost:3001", 
    "http://127.0.0.1:3001", 
    "http://localhost:5173", 
    "http://127.0.0.1:5173"
}, maxAge = 3600, allowCredentials = "true")
public class AiCharactersController {

    @Autowired
    private AiCharactersService aiCharactersService;

    /**
     * 获取角色列表
     */
    @ApiOperation("获取角色列表")
    @GetMapping
    public Result<List<AiCharacters>> getCharacterList(
            @ApiParam("角色类型") @RequestParam(required = false) String characterType,
            @ApiParam("是否启用") @RequestParam(required = false) Boolean isActive) {
        
        List<AiCharacters> characters = aiCharactersService.getCharacterList(characterType, isActive);
        return Result.success(characters);
    }

    /**
     * 获取角色详情
     */
    @ApiOperation("获取角色详情")
    @GetMapping("/{id}")
    public Result<AiCharacters> getCharacterDetail(
            @ApiParam("角色ID") @PathVariable Long id) {
        
        AiCharacters character = aiCharactersService.getById(id);
        if (character == null) {
            return Result.error("角色不存在");
        }
        return Result.success(character);
    }

    /**
     * 获取角色状态
     */
    @ApiOperation("获取角色状态")
    @GetMapping("/status/{id}")
    public Result<CharacterStatusVO> getCharacterStatus(
            @ApiParam("角色ID") @PathVariable Long id) {
        
        CharacterStatusVO status = aiCharactersService.getCharacterStatus(id);
        if (status == null) {
            return Result.error("角色不存在");
        }
        return Result.success(status);
    }
}

